import { ref } from "vue";
import { ThemeColorsType } from "../interface";

export const basePath = "/";
export const assetsDir = "assets";
export const buildCommand = "serve";
const getRecuitUrl = (path: string) => {
  if (path.includes("recurit_url=")) {
    const url = path.split("recurit_url=")[1];
    return decodeURI(url);
  }
  return "";
};
export const getHash = (exclueLogin = false) => {
  const path = window.location.hash?.replace("#", "");
  return exclueLogin
    ? path.includes("/login")
      ? getRecuitUrl(path)
      : path
    : path;
};
export const getThemeColors = () => {
  return ref<ThemeColorsType[]>([
    /* 道奇蓝（默认） */
    { color: "#1b2a47", themeColor: "default" },
    /* 亮白色 */
    { color: "#ffffff", themeColor: "light" },
    /* 猩红色 */
    { color: "#f5222d", themeColor: "dusk" },
    /* 橙红色 */
    { color: "#fa541c", themeColor: "volcano" },
    /* 金色 */
    { color: "#fadb14", themeColor: "yellow" },
    /* 绿宝石 */
    { color: "#13c2c2", themeColor: "mingQing" },
    /* 酸橙绿 */
    { color: "#52c41a", themeColor: "auroraGreen" },
    /* 深粉色 */
    { color: "#eb2f96", themeColor: "pink" },
    /* 深紫罗兰色 */
    { color: "#722ed1", themeColor: "saucePurple" }
  ]);
};

/** hex转rgb */
function hexToRgb(str: string) {
  const hxs = str.replace("#", "").match(/../g) as any;
  for (let i = 0; i < 3; i++) hxs[i] = parseInt(hxs[i], 16);
  return hxs;
}

/** rgb转hex */
function rgbToHex(a: any, b: any, c: any) {
  const hexs = [a.toString(16), b.toString(16), c.toString(16)];
  for (let i = 0; i < 3; i++) {
    if (hexs[i].length == 1) hexs[i] = `0${hexs[i]}`;
  }
  return `#${hexs.join("")}`;
}

/** 加深颜色值 */
export function darken(color: string, level: number) {
  const rgbc = hexToRgb(color);
  for (let i = 0; i < 3; i++) rgbc[i] = Math.floor(rgbc[i] * (1 - level));
  return rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
}

/** 变浅颜色值 */
export function lighten(color: string, level: number) {
  const rgbc = hexToRgb(color);
  for (let i = 0; i < 3; i++)
    rgbc[i] = Math.floor((255 - rgbc[i]) * level + rgbc[i]);
  return rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
}
